package cn.myblog.ainblog.conroller.backstage;

import cn.myblog.ainblog.model.LogModel;
import cn.myblog.ainblog.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

/**
 * @author Dovaior
 * @Description 时间线的控制器
 * @create 2021-05-03 08:38
 **/
@Controller
@RequestMapping("/backstage")
public class BackstageTimeLineController {
    @Autowired
    private LogService logService;

    @GetMapping("/timeLine")
    public String timeLine(Model model){
        Map<String, Integer> countMap = logService.queryAllCount();
        model.addAttribute("countMap",countMap);
        return "backstage/backstage-timeLine";
    }

    /**
     * 查询全部log
     * @param model 封装载体
     * @return 返回信息
     */
    @ResponseBody
    @GetMapping("/queryTimeLine")
    public List<LogModel> queryAllLog(Model model){
        List<LogModel> logList = logService.queryAllLog();
        model.addAttribute("logList",logList);
        return logList;
    }

    /**
     * 查询全部种类的操作次数
     * @return 返回封装了信息的map
     */
    @ResponseBody
    @GetMapping("/queryAllCount")
    public Map<String,Integer> queryAllCount(){
        return logService.queryAllCount();
    }
}
